package org.liang.code.rabbitMQ.路由模式;

import com.rabbitmq.client.*;
import org.liang.code.rabbitMQ.utils.RabbitConstant;
import org.liang.code.rabbitMQ.utils.RabbitUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Sina {

    private static final Logger logger = LoggerFactory.getLogger(Sina.class);

    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = RabbitUtils.getConnection();
        final Channel channel = connection.createChannel();
        channel.basicQos(1);
        channel.basicConsume(RabbitConstant.QUEUE_SINA, false, new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
                                       byte[] body) throws IOException {
                logger.info("新浪收到气象信息：{}", new String(body));
                channel.basicAck(envelope.getDeliveryTag(), false);
            }
        });

    }
}
